/**
 * Created by Lwang on 2017-03-30.
 */
import Util from "utils"

var productDetailCtrl = ['$scope', '$stateParams', '$state', '$location', '$http', '$timeout', '$rootScope', 'Http',function ($scope, $stateParams, $state, $location, $http, $timeout, $rootScope, Http) {

    var id = $state.params.productId;

    $scope.detail = "";
    Http.request({
        url: Util.ajax.investView(id),
        method: "get",
        success: function (res) {
            Http.handler(Util.merge(res,{
                success:function (res) {
                    var alldata = res;
                    Http.request({
                        url: Util.ajax.CarType,
                        method: "get",
                        success: (data) => {
                            alldata["carchange"] = data;
                            $scope.detail = alldata;

                        }
                    });
                }
            }));
        }
    });

    $scope.seeLocation = function () {
        location.href='http://m.jshrdtz.com/map.html'
    };

    $scope.carExchange = function (car, carList) {
        if (Util.getType(carList) == "array") {
            for (let i = 0; i < carList.length; i++) {
                if (carList[i].hasOwnProperty(car)) {
                    return carList[i][car];
                }
            }
        }

    };


    //到期时间处理
    $scope.dateCancle = function (time) {
        var date = new Date(time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return year + "-" + month + "-" + day;
    };
    //投资周期处理
    $scope.monthCancle = function (day) {
        return Math.round(day / 30);
    };
}];
export {productDetailCtrl};